package com.zjl.servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zjl.dao.impl.StudentDaoImpl;
import com.zjl.entity.StudentEntity;
import com.zjl.util.BaseServlet;

/**
 * Servlet implementation class StudentServlet1
 */
public class StudentServlet1 extends BaseServlet {
	StudentDaoImpl sDaoImpl = new StudentDaoImpl();
	public void selectAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String name = request.getParameter("name");
		ArrayList<StudentEntity> arrayList = sDaoImpl.selectAll(name);
		request.setAttribute("alist", arrayList);
		request.setAttribute("name",name);
		request.getRequestDispatcher("list.jsp").forward(request, response);
	}
	public void userDetail(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int id=Integer.parseInt(request.getParameter("id"));
		StudentEntity list=sDaoImpl.userDetail(id);
		  request.setAttribute("user", list);
		request.getRequestDispatcher("userDetail.jsp").forward(request, response);
	}
	public void studentAdd(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String stuName=request.getParameter("stuName");
		String sex=request.getParameter("sex");
		String mtel=request.getParameter("mtel");
		String qq=request.getParameter("qq");
		String address=request.getParameter("address");
		String className=request.getParameter("className");
		int result=sDaoImpl.studentAdd(new StudentEntity(0, stuName, sex, mtel, qq, address, className));
		if (result>0) {
			response.sendRedirect("StudentServlet1?req=selectAll");
		}else {
			request.setAttribute("msg", "添加失败");
			request.getRequestDispatcher("studentadd.jsp").forward(request, response);
		}
	}

}
